#include <stdio.h>
#include <string.h>
#define Max 34809



main()
{
	char shu[Max];
	int   an[3005];
	int i,n,j,k,a,b;

	memset(shu,0,sizeof(shu));
	memset(an,0,sizeof(an));
	
	for (i=2;an[0]<=3000;i++)
	{
		if (shu[i]==0)
		{
			an[++an[0]]=i;
			shu[i]=1;
			k=0;
			for (a=i+1;a<Max;a++)
			{
				if (shu[a]==0)
				{
					k++;
					if (k==i) 
					{
						shu[a]=-1;
						k=0;
					}
				}



			}
				
		}
	}

/*	for (i=1;i<=20;i++)
		printf("%d ", an[i]);
	printf("\n");
*/	while (1)
	{
		scanf("%d", &a);
		if (a==0) break;
		printf("%d\n", an[a]);
	}
	


	return 0;

}
